import {replaceAll} from '../Utils/index'

/**
 * @author 林间有风Lin
 * @version 1.0
 * @description 生成自定义标签
 * @param tagName DOM标签结构，审查时会用到
 * @param component 标签组件
 */
const attach = (tagName: string, component: any):void => {
    if(tagName.indexOf('-') === -1){  // 校错机制，为了性能，不会处理过多逻辑
        tagName = replaceAll(tagName, /[A-Z]/, (origin: string, index: number, len: number) =>
         index === 0 ? origin.toLowerCase() : '-' + origin.toLowerCase()) 
    }
    window.customElements.define(tagName, component);
  }

export { attach }